//
//  QDHomeController.m
//  simulateQuickDoctor
//
//  Created by 梁家伟 on 17/3/22.
//  Copyright © 2017年 PipiXia. All rights reserved.
//

#import "QDHomeController.h"
#import "QDNetworkTool.h"
#import <YYModel.h>
#import "QDCyclePictureView.h"
#import "QDBookDoctorController.h"
#import "QDCyclePictureView.h"
#import "QDWeatherModel.h"
#import <UIImageView+WebCache.h>
#import "SDCycleScrollView.h"
#import "QDCyclePicModel.h"
#import "QDScrollLabelView.h"
#import "QDDetailController.h"


@interface QDHomeController ()
@property (weak, nonatomic) IBOutlet UIImageView *weatherImageView;

/**
 温度
 */
@property (weak, nonatomic) IBOutlet UILabel *temperatureLabel;

/**
 风级
 */
@property (weak, nonatomic) IBOutlet UILabel *windLabel;

/**
 天气
 */
@property (weak, nonatomic) IBOutlet UILabel *weatherLabel;

/**
 滚动视图
 */
@property (weak, nonatomic) IBOutlet QDScrollLabelView *scrollLabelView;

/**
 轮播
 */
@property (weak, nonatomic) IBOutlet QDCyclePictureView *cyclePicView;

//天气模型
@property(nonatomic,strong)QDWeatherModel *weatherModel;


@end

@implementation QDHomeController

static NSUInteger baseTag = 500;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor darkGrayColor];
    
}

-(instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    if(self = [super initWithCoder:aDecoder]){
        [self loadWeatherData];
    }
    return self;
}


//加载天气
-(void) loadWeatherData {
    //显示天气的key
    NSString *key = @"17IvzuqmKrK1cGwNL6VQebF9";
    NSString *urlString = @"http://api.map.baidu.com/telematics/v3/weather";
    
    //参数
    NSDictionary *parameters = @{@"location":@"深圳",@"output":@"json",@"ak":key};
    
    //利用网络工具类发起GET请求
    [[QDNetworkTool sharedTool] requestWithHTTPMethod:@"GET" URLString:urlString parameters:parameters CallBack:^(id responseObj) {
        
//        NSLog(@"%@",[NSThread currentThread]);
        
//        NSLog(@"%@",responseObj);
        
        
        //反序列化
//        NSDictionary *responseObjDict = [NSJSONSerialization JSONObjectWithData:responseObj options:0 error:NULL];
        //取到result数组
        NSArray *resultArr = responseObj[@"results"];
        NSDictionary *resultDict = resultArr.firstObject;
        //取出天气的那个数组
        NSArray *weatherArr = resultDict[@"weather_data"];
        NSDictionary *weatherDict = weatherArr.firstObject;
        
        _weatherModel = [QDWeatherModel weatherWithDict:weatherDict];
        
        
        //赋值真实数据
//        [_weatherImageView sd_setImageWithURL:[NSURL URLWithString:_weatherModel.nightPictureUrl]];
        _temperatureLabel.text = _weatherModel.temperature;
        _windLabel.text = _weatherModel.wind;
        _weatherLabel.text = [NSString stringWithFormat:@"深圳(%@) %@",_weatherModel.weather,_weatherModel.date];
        
    }];
    
}





- (IBAction)sicknessSelect:(UIButton*)sender{
    
    NSUInteger index = sender.tag - baseTag;

    if(index != 6){
        QDBookDoctorController* vc = [[QDBookDoctorController alloc]init];
        vc.model.ci1_id = index;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
    
        //当点击公益活动时候跳转到网页
        QDDetailController *detailVC = [[QDDetailController alloc]init];
        //push出详细页面
        [self.navigationController pushViewController:detailVC animated:YES];
    }
}
@end
